﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admincp_monhoc : System.Web.UI.Page
{
    QuanLyHocSinhDatabaseDataContext db = new QuanLyHocSinhDatabaseDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        this.FillDataToListview();
    }
    protected void lvMonhoc_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {

    }
    protected void lvMonhoc_ItemEditing(object sender, ListViewEditEventArgs e)
    {

    }
    protected void lvMonhoc_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "EDIT":
                Response.Redirect("qlmonhoc.aspx?hanhdong=capnhat&mamonhoc=" + e.CommandArgument.ToString());
                break;
            case "DELETE":
                MonHoc monhoc = db.MonHocs.Single(mh => mh.MaMonHoc == e.CommandArgument.ToString());
                db.MonHocs.DeleteOnSubmit(monhoc);
                db.SubmitChanges();
                this.FillDataToListview();
                break;
        }
    }
    protected void lvMonhoc_ItemDataBound(object sender, ListViewItemEventArgs e)
    {

    }

    protected void ThemMoiMonHoc(object sender, EventArgs e) //Phương thức thêm mới giáo viên
    {
        Response.Redirect("qlmonhoc.aspx?hanhdong=themmoi");
    }

    protected string HienThiTrangThaiBangHinhAnh(object TrangThai)
    {
        if (TrangThai != null)
        {
            if ((bool)TrangThai)
                return "images/active.png";
            else
                return "images/inactive.png";
        }
        else
            return "images/inactive.png";
    }

    private void FillDataToListview() //đổ dữ liệu vào listview môn học
    {
        lvMonhoc.DataSource = db.MonHocs;
        lvMonhoc.DataBind();
    }
}